package top.malegod.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import top.malegod.model.User;
import top.malegod.service.OtherService;
import top.malegod.utils.ServerResponse;

import javax.servlet.http.HttpSession;

/**
 * Create by IntelliJ IDEA
 *
 * @author: AbelEthan
 * @date-Time: 2018/6/7 19:01
 * @description: 其他操作
 */
@Controller
@RequestMapping("/other")
public class OtherController {

    @Autowired
    private OtherService otherService;

    /**
     * 我的积分
     * @param session
     * @return
     */
    @RequestMapping(value = "/findUserIntegral.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse findUserIntegral(HttpSession session){
        User user = (User) session.getAttribute("user");
        if (user == null){
            return ServerResponse.createError("用户未登录，请先登录");
        }
        ServerResponse response = otherService.findUserIntegral(user.getId());
        return response;
    }

    /**
     * 我的等级
     * @param id
     * @return
     */
    @RequestMapping(value = "/findUserRank.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse findUserRank(String id){
        ServerResponse response = otherService.findUserRank(id);
        return response;
    }

    /**
     * 获取分类名
     * @param id
     * @return
     */
    @RequestMapping(value = "/findCategoryName.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse findCategoryName(String id){
        ServerResponse response = otherService.findCategoryName(id);
        return response;
    }

    /**
     * 获取个人评论
     * @param session
     * @return
     */
    @RequestMapping(value = "findUserComments.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse findUserComments(HttpSession session){
        User user = (User) session.getAttribute("user");
        if (user == null){
            return ServerResponse.createError("你还没登录，请先登录");
        }
        ServerResponse response = otherService.findUserComments(user.getId());
        return response;
    }
}
